home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / utility / 406 / utility2 / antibomb.doc < prev    next >
Text File  |  1989-08-18  |  8KB  |  244 lines

  1. Program Name:       ANTIBOMB.PRG                   
  2. Written By:         Greg Baker
  3. Distributed by:     Inland Specialty Products
  4.  
  5.  
  6.      If  you're  tired  of  the cherry  bombs  or  mushroom  clouds
  7.  
  8. displayed  when  a program crashes then you'll  find  this  utility
  9.  
  10. essential.  It  replaces the bombs with a user friendly  alert  box
  11.  
  12. that identifies the error in English.  It runs from the Desktop  or
  13.  
  14. from the AUTO folder. For all STs, all resolutions.
  15.  
  16.  
  17.      A couple of weeks ago, I was testing a new program which I had
  18.  
  19. written  when  something terrible happened.  Those  strange  little
  20.  
  21. cherry  bombs appeared on the screen.  What did  they  mean?  After
  22.  
  23. thumbing through my pile of ST books (I know the error descriptions
  24.  
  25. are in them somewhere) I discovered I had a BUS ERROR. Why couldn't
  26.  
  27. the system tell me that!
  28.  
  29.  
  30.      Now I don't have to scramble for my books anymore;  I've  made
  31.  
  32. my ST more intelligent.  Instead of those little bombs I now get an
  33.  
  34. Alert box which displays the error message in text format -- and so
  35.  
  36. can you!
  37.  
  38.  
  39. Changing the Exceptions
  40.  
  41.      The  instructions  for using ANTIBOMB  are  very  simple.  The
  42.  
  43. program is named ANTIBOMB.PRG on the accompanying disk. You may run
  44.  
  45. it from the GEM Desktop or place it in the AUTO folder on your boot
  46.  
  47. disk  if you'd like it to be installed automatically when you  turn
  48.  
  49. on your ST.  It's very short,  so it doesn't take much memory  from
  50.  
  51. the system.
  52.  
  53.  
  54.      So  what does it do?  It replaces the bombs with an Alert  box
  55.  
  56. that  describes  what  the  error  is.   It  also  gives  you   the
  57.  
  58. opportunity,  depending  on the exception type to  either  continue
  59.  
  60. with the program, terminate the program,  or reboot(warm or cold)
  61.  
  62. the system.
  63.  
  64.  
  65. So What is an Exception?
  66.  
  67.      An exception allows the 68000 to interupt what it is doing, go
  68.  
  69. do  something else,  then go back to the task that  was  originally
  70.  
  71. interupted. ANTIBOMB.PRG traps the following exceptions:
  72.  
  73.  
  74. Bus Error:               An  exception  is  generated whenever  the
  75.                          BERR signal is asserted by external logic.
  76.  
  77. Address Error:           An  attempt to  access  either  word  data,
  78.                          long word data, or an instruction at an odd
  79.                          address.
  80.  
  81. Illegal Instruction:     System  tried  to  process  an   invalid
  82.                          opcode.
  83.  
  84. Divide by Zero:          System tried to divide a number by zero.
  85.  
  86. CHK instruction:         Does  a  boundary  check   to see if the
  87.                          contents  of  a data register are in the
  88.                          range  from  zero  to  an  upper  limit.
  89.                          If less then  zero  or greater  than the
  90.                          upper  limit  this  exception  will  be
  91.                          generated.
  92.  
  93. TRAPV Instruction:       If the overflow bit (bit 1) in the status
  94.                          register is set when this instruction is
  95.                          executed then an exception is generated.
  96.  
  97. Privileged Instruction:  An exception will be generated if the
  98.                          following instructions are executed in
  99.                          USER mode; STOP, RESET, RTE, MOVE to SR,
  100.                          AND immediate to SR, EOR immediate to SR,
  101.                          OR immediate to SR, and MOVE USP.
  102.  
  103. Trace Trap:    If the T-bit (bit 15) in the status register is set
  104.                then  an  exception will be  generated  after  each
  105.                instruction. This is useful for program debugging.
  106.  
  107.  
  108. How it Works
  109.  
  110.      ANTIBOMB  is a terminate and stay resident program written  in
  111.  
  112. Mark Williams C. It redirects the above exception vectors to itself
  113.  
  114. and then waits for an exception to occur.  When an exception occurs
  115.  
  116. an  Alert box is displayed notifying the user which  exception  has
  117.  
  118. occured  and  gives  the opportunity to either  continue  with  the
  119.  
  120. program, terminate the program, or reboot(warm or cold) the system.
  121.  
  122.  
  123. PROGRAM FLOW
  124.  
  125.      First,  appl_init  is called to register the program with  the
  126.  
  127. AES.  This  allows the Alert box to be displayed when an  exception
  128.  
  129. occurs.      Then, Setexc is used to redirect the exception vectors
  130.  
  131. so  they point to specific routines within ANTIBOMB.  For  example,
  132.  
  133. the  line Setexc(BUS_ERROR,bus_error) sets the exception vector  so
  134.  
  135. that  whenever  a Bus Error occurs the bus_error  routine  will  be
  136.  
  137. executed.
  138.  
  139.      Since all the exception routines function in the same way only
  140.  
  141. the  bus_error routine will be discussed in detail.  The  bus_error
  142.  
  143. routine first calls setexc routine so that the registers are  saved
  144.  
  145. and  the  stack pointer is re-adjusted to allow processing  of  the
  146.  
  147. retexc routine. This allows the CONTINUE button in the alert box to
  148.  
  149. pass  control  back to the interupted program or to  terminate  the
  150.  
  151. program depending on the exception type.  The display routine  will
  152.  
  153. take the message passed from bus_error and display it in the  Alert
  154.  
  155. box.  This  routine  also passes the error_code which  is  used  to
  156.  
  157. determine  whether the program should continue  or  terminate.  The
  158.  
  159. User  is then given the opportunity to either return  and  continue
  160.  
  161. with the program,  terminate the program,  or reboot(warm or  cold)
  162.  
  163. the ST.
  164.  
  165.      If   continue  is  selected  then  ANTIBOMB  will  check   the
  166.  
  167. error_code to see if the program should be continued or terminated.
  168.  
  169. If  the error_code says continue then ANTIBOMB will return  to  the
  170.  
  171. interupted program and continues execution. This return is executed
  172.  
  173. by  the retexc routine in module setexc.s.  Retexc will retore  the
  174.  
  175. saved  registers then return to the interupted program via the  RTE
  176.  
  177. instruction. If the error_code says to terminate then ANTIBOMB will
  178.  
  179. use the PTERM() function to abort the program.
  180.  
  181.  
  182.      If a warm reboot is selected then ANTIBOMB jumps to the  reset
  183.  
  184. address contained in memory location 0x004. This memory location is
  185.  
  186. also  used when the reset button is pressed.  If a cold  reboot  is
  187.  
  188. selected  then  magic  number  located at  0x420  which  tells  the
  189.  
  190. operating system that a coldstart was sucessfully done is cleared.
  191.  
  192. ANTIBOMB  then jumps to the start of the operating system  (0x5000)
  193.  
  194. and a cold restart is performed.
  195.  
  196.  
  197.  
  198. So Who gets Terminated?
  199.  
  200.      As  stated previously when some exceptions occur  the  program
  201.  
  202. will  be aborted when the continue but is  pressed.  The  following
  203.  
  204. table  identifies each of the exceptions and whether they  continue
  205.  
  206. or terminate.
  207.  
  208.   Exception Type             ERROR_CODE=
  209.      Buss Error               Terminate
  210.      Address Error            Terminate
  211.      Illegal Instruction      Continue
  212.      Divide by Zero           Continue
  213.      Check Instruction        Continue
  214.      TrapV Instruction        Continue
  215.      Privilege Instruction    Continue
  216.      Trace Trap               Continue
  217.  
  218.  
  219.  
  220.  
  221. Let's try it
  222.  
  223.      First  execute the ANTIBOMB.PRG program from the  Desktop  (or
  224.  
  225. AUTO folder). Now, run the EXCEPTION.PRG program. First you will be
  226.  
  227. notified  of a DIVIDE BY ZERO error.  Press CONTINUE.  The  Desktop
  228.  
  229. will be redisplayed. Now, run the EXCEPTION.PRG program again. This
  230.  
  231. time press REBOOT. The ST will reboot.
  232.  
  233.  
  234.  
  235. Want the Source???
  236.  
  237.      Mark Williams C was used to develop this utility. The source is
  238.  
  239. available for $5.00 from:
  240.  
  241.                     Inland Specialty Products
  242.                     N. 4112 Simpson Rd.
  243.                     Otis Orchards, Wa. 99027
  244.